<template>
  <view class="distribution-posters">
    <view class="slider-banner banner">
      <swiper indicatorDots="true">
        <block v-for="(item, infoIndex) in info" :key="infoIndex">
          <swiper-item>
            <image class="slide-image" :src="item.wap_poster" mode="widthFix" show-menu-by-longpress />
          </swiper-item>
        </block>
      </swiper>
    </view>
  </view>
</template>
<script>
	import {
		mapGetters
	} from "vuex";
  import { getSpreadImg } from "@/api/user";
  export default {
    name: "Poster",
    components: {},
    data: function () {
      return {
        info: [],
        activeIndex: 0
      };
    },
    onShow: function () {
	  this.$store.dispatch('getUser', true).then(res =>{
		  this.getIndex();
	  })
    },
	computed: mapGetters(["userInfo"]),
    methods: {
      getIndex: function () {
        let that = this;
		if(this.userInfo.nickname == '' || this.userInfo.nickname == '微信用户' || this.userInfo.nickname == null){
			uni.showModal({
				title: '温馨提示',
				content: '请完善用户昵称和头像',
				success: function(res) {
					if (res.confirm) {
						this.$yrouter.push({
							path: '/pages/user/PersonalData/index'
						})
					} else if (res.cancel) {
						uni.navigateBack(1)
					}
				}.bind(this)
			});
			return
		}
		uni.showLoading({
			title: "加载中"
		});
        getSpreadImg({
          from: this.$deviceType == 'weixin' || this.$deviceType == 'weixinh5' ? 'uniappH5' : this.$deviceType
        }).then(
          res => {
			uni.hideLoading();
            that.info = res.data;
          },
          err => {
			uni.hideLoading();
            uni.showToast({
              title: err.msg || err.response.data.msg || err.response.data.message,
              icon: "none",
              duration: 2000
            });
          }
        );
      },
      downloadIamge (imgsrc, name) {
        var that = this;
        this.isDown = true;
        var downloadUrl = imgsrc;

        if (!wx.saveImageToPhotosAlbum) {
          uni.showModal({
            title: "提示",
            content: "当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。"
          });
          that.openDialogVisible = true;

          return;
        }
      },
      saveImg: function () {
        this.downloadIamge(
          this.info[this.activeIndex].wap_poster,
          "poster" + this.activeIndex
        );
      },
      downloadFile(url){
        uni.downloadFile({
          url,
          fail: function(res) {
            uni.showModal({
            title: "提示",
            content: "保存失败"
          });
          },
          success: function(res) {
            uni.showModal({
            title: "提示",
            content: "保存成功"
          });
          }
        });
      }
    }
  };
</script>

<style lang="less">
  page {
    height: 100%;
  }

  .distribution-posters {
    height: 100%;
  }

  .banenr {
    height: 100%;
  }

  .banner swiper {
    height: 100%;
  }

  .banner .slide-image {
    width: 100%;
    height: auto;
  }
</style>
